find_package(GTest REQUIRED)

set(GTEST_LIBS  GTest::gtest GTest::gtest_main pthread)

add_executable(skiplist_test   skiplist_test.cpp)
target_link_libraries(skiplist_test PRIVATE ${GTEST_LIBS})

add_executable(lru_cache_test   lru_cache_test.cpp)
target_link_libraries(lru_cache_test PRIVATE ${GTEST_LIBS})

add_executable(mempool_test   mempool_test.cpp   ${CMAKE_SOURCE_DIR}/src/mempool.cpp)
target_link_libraries(mempool_test PRIVATE ${GTEST_LIBS})
#target_include_directories(mempool_test PRIVATE ${CMAKE_SOURCE_DIR}/include)

add_executable(socket_test   socket_test.cpp   ${CMAKE_SOURCE_DIR}/src/socket.cpp)
target_link_libraries(socket_test PRIVATE ${GTEST_LIBS})

add_executable(acceptor_test   acceptor_test.cpp   ${CMAKE_SOURCE_DIR}/src/acceptor.cpp  
${CMAKE_SOURCE_DIR}/src/socket.cpp ${CMAKE_SOURCE_DIR}/src/channel.cpp  
${CMAKE_SOURCE_DIR}/src/acceptor.cpp  ${CMAKE_SOURCE_DIR}/src/eventloop.cpp  ${CMAKE_SOURCE_DIR}/src/epoll_poller.cpp )
target_link_libraries(acceptor_test PRIVATE ${GTEST_LIBS})

add_executable(channel_test   channel_test.cpp   ${CMAKE_SOURCE_DIR}/src/channel.cpp  
${CMAKE_SOURCE_DIR}/src/eventloop.cpp  ${CMAKE_SOURCE_DIR}/src/epoll_poller.cpp )
target_link_libraries(channel_test PRIVATE ${GTEST_LIBS})

add_executable(epoll_poller_test   epoll_poller_test.cpp   ${CMAKE_SOURCE_DIR}/src/channel.cpp  
${CMAKE_SOURCE_DIR}/src/epoll_poller.cpp ${CMAKE_SOURCE_DIR}/src/eventloop.cpp)
target_link_libraries(epoll_poller_test PRIVATE ${GTEST_LIBS})

add_executable(eventloop_test   eventloop_test.cpp   ${CMAKE_SOURCE_DIR}/src/channel.cpp  
${CMAKE_SOURCE_DIR}/src/epoll_poller.cpp ${CMAKE_SOURCE_DIR}/src/eventloop.cpp)
target_link_libraries(eventloop_test PRIVATE ${GTEST_LIBS})

add_executable(tcpconnection_test   tcpconnection_test.cpp   ${CMAKE_SOURCE_DIR}/src/channel.cpp  
${CMAKE_SOURCE_DIR}/src/epoll_poller.cpp ${CMAKE_SOURCE_DIR}/src/eventloop.cpp  ${CMAKE_SOURCE_DIR}/src/tcpconnection.cpp)
target_link_libraries(tcpconnection_test PRIVATE ${GTEST_LIBS})

add_executable(tcp_server_integration_test   tcp_server_integration_test.cpp   ${CMAKE_SOURCE_DIR}/src/channel.cpp  
${CMAKE_SOURCE_DIR}/src/epoll_poller.cpp ${CMAKE_SOURCE_DIR}/src/eventloop.cpp  ${CMAKE_SOURCE_DIR}/src/tcpconnection.cpp
${CMAKE_SOURCE_DIR}/src/acceptor.cpp  ${CMAKE_SOURCE_DIR}/src/socket.cpp  ${CMAKE_SOURCE_DIR}/src/tcpserver.cpp)
target_link_libraries(tcp_server_integration_test PRIVATE ${GTEST_LIBS})


add_test(NAME MemoryPoolTest COMMAND mempool_test)
add_test(NAME SkipListTest COMMAND skiplist_test)
add_test(NAME LRUCacheTest COMMAND lru_cache_test)
add_test(NAME SocketTest COMMAND socket_test)
add_test(NAME AcceptorTest COMMAND acceptor_test)
add_test(NAME ChannelTest COMMAND channel_test)
add_test(NAME Epoll_pollerTest COMMAND epoll_poller_test)
add_test(NAME EventloopTest COMMAND eventloop_test)
add_test(NAME TcpconnectionTest COMMAND tcpconnection_test)
add_test(NAME tcp_server_integrationTest COMMAND tcp_server_integration_test)